﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mvp.DTO;

namespace Mvp.DataAccess
{
    public interface IBookMapper
    {
        IList<BookDTO> GetAllBooks();

        BookDTO FindById(int bookID);
    }

    public class SimpleBookMapper : IBookMapper
    {
        private readonly IList<BookDTO> _list;

        public SimpleBookMapper()
        {
            _list = new List<BookDTO>()
            {
                new BookDTO(){ID = 1,Title="Head First Design Patterns",PubDate=DateTime.Now.AddDays(-10),Price=67.5M},
                new BookDTO(){ID = 2,Title="Head First Java",PubDate=DateTime.Now.AddDays(10),Price=57.5M},
                new BookDTO(){ID = 3,Title="Head First C#",PubDate=DateTime.Now.AddDays(20),Price=167.5M},
                new BookDTO(){ID = 4,Title="Head First Design C++",PubDate=DateTime.Now.AddDays(-20),Price=267.5M},
                new BookDTO(){ID = 5,Title="Head First Design PHP",PubDate=DateTime.Now.AddDays(30),Price=367.5M},
            };
        }

        #region IBookMapper 成员

        public IList<BookDTO> GetAllBooks()
        {
            return new List<BookDTO>(_list);
        }

        public BookDTO FindById(int bookID)
        {
            var result = (from s1 in _list
                          where s1.ID == bookID
                          select s1).FirstOrDefault();
            return result;
        }

        #endregion
    }
}
